#include "optionset.h"

const QMap<int,QList<OptionSet::OptionSetStruct> > OptionSet::_optionMap=
{
    {OptionSet::SP_BaudRate,{
         {"200",200},{"300",300},{"600",600},{"1200",1200},{"1800",1800},{"2400",2400},{"4800",4800},
         {"9600",9600},{"14400",14400},{"19200",19200},{"9600",9600},{"38400",38400},{"56000",56000},
         {"57600",57600},{"76800",76800},{"115200",115200},{"128000",128000},{"256000",256000},
      }
    },
    {OptionSet::SP_DataBits,{
        {"5",5},{"6",6},{"7",7},{"8",8},
      }
    },
    {OptionSet::SP_Parity,{
        {"None",QSerialPort::NoParity},
        {"Even",QSerialPort::EvenParity},
        {"Odd",QSerialPort::OddParity},
        {"Space",QSerialPort::SpaceParity},
        {"Mark",QSerialPort::MarkParity},
      }
    },
    {OptionSet::SP_StopBits,{
         {"1",QSerialPort::OneStop},
         {"1.5",QSerialPort::OneAndHalfStop},
         {"2",QSerialPort::TwoStop},
      }
    },

};


OptionSet::OptionSet(QObject *parent):
    QObject (parent)
{

}


int OptionSet::initComboBox(QComboBox *cmb,int option_type)
{
    if(cmb==nullptr)
    {
        qDebug()<<"cmb is NULL!";
        return -1;
    }

    if(!_optionMap.contains(option_type))
    {
        qDebug()<<"didn't find the option_type: "<<option_type<<" !";
        return -2;
    }

    for(const OptionSet::OptionSetStruct& ops:_optionMap[option_type])
    {
        cmb->addItem(ops.text,ops.var);
    }
    cmb->setCurrentIndex(-1);
    cmb->setProperty("option_type",option_type);
    return 0;
}




